package org.kineticsproject.application.util;

import java.io.File;
import java.io.IOException;
import java.sql.Date;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;

import data.DataFactory;
import data.Person;
import data.Population;
import data.Exercise;

public class PopulatePopulation {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		
		Population population = DataFactory.eINSTANCE.createPopulation();
		
		Person person = DataFactory.eINSTANCE.createPerson();
		person.setHeight((float) 70.2);
		person.setName("Casey Kelso");
		person.setWeight((float)72.8);
		Date d = new Date(0);
		person.setDateOfBirth(d);
		
		/*Exercise exercise0 = DataFactory.eINSTANCE.createExercise();
		exercise0.setEnergyExpenditure(1500);
		exercise0.setName("Desert Classic Out and Back");
		exercise0.setSport(data.Sport.MOUNTAIN_BIKING);
		exercise0.setTimestamp(new Date(0));
		
		Exercise exercise1 = DataFactory.eINSTANCE.createExercise();
		exercise1.setEnergyExpenditure(2000);
		exercise1.setName("Grand Canyon - Down Kaibab Up Bright Angel");
		exercise1.setSport(data.Sport.HIKING);
		exercise1.setTimestamp(new Date(0));
		*/
		//person.getExercises().add(exercise0);
		//person.getExercises().add(exercise1);
		
		

		
		population.getPeople().add(person);
		
		Person person2 = DataFactory.eINSTANCE.createPerson();
		person2.setHeight((float)63.2);
		person2.setName("Abby Kelso");
		person2.setWeight((float)61.2);
		
		population.getPeople().add(person2);
		/*
		Exercise exercise2 = DataFactory.eINSTANCE.createExercise();
		exercise2.setEnergyExpenditure(800);
		exercise2.setName("3 Laps Midway Village");
		exercise2.setSport(data.Sport.RUNNING);
		exercise2.setTimestamp(new Date(0));
		
		person2.getExercises().add(exercise2);
			*/
		//Create new ResourceSet & Resource
		ResourceSet resourceSet = new ResourceSetImpl();
		
		// Register XML resource factory
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", 
		new XMIResourceFactoryImpl());

		Resource resource = resourceSet.createResource(URI.createFileURI(new File("myPopulation.xmi").getAbsolutePath()));

		// add the root object to the resource
		resource.getContents().add(population);
		// serialize resource – you can specify also serialization
		// options which defined on org.eclipse.emf.ecore.xmi.XMIResource
		resource.save(null);


	}

}